<!doctype html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Zabbix," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.1" />






<meta name="description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;需要对特定服务进行监控，于是，通过编写脚本获取各个进程占用系统资源的信息，从而使用zabbix采集到这些数据进行特定进程的基础监控。 &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;主要需要监控的程序如下： &amp;#160;&amp;#160;&amp;#160;&amp;#160;">
<meta name="keywords" content="Zabbix">
<meta property="og:type" content="article">
<meta property="og:title" content="zabbix监控进程的CPU和内存占用量">
<meta property="og:url" content="https://hcldirgit.github.io/2017/09/03/Zabbix/17. zabbix监控进程的CPU和内存占用量/index.html">
<meta property="og:site_name" content="失落的乐章">
<meta property="og:description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;需要对特定服务进行监控，于是，通过编写脚本获取各个进程占用系统资源的信息，从而使用zabbix采集到这些数据进行特定进程的基础监控。 &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;主要需要监控的程序如下： &amp;#160;&amp;#160;&amp;#160;&amp;#160;">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/zabbix%E7%9B%91%E6%8E%A7%E8%BF%9B%E7%A8%8B%E7%9A%84CPU%E5%92%8C%E5%86%85%E5%AD%98%E5%8D%A0%E7%94%A8%E9%87%8F/01.jpeg?raw=true">
<meta property="og:updated_time" content="2017-09-02T17:39:04.311Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="zabbix监控进程的CPU和内存占用量">
<meta name="twitter:description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;需要对特定服务进行监控，于是，通过编写脚本获取各个进程占用系统资源的信息，从而使用zabbix采集到这些数据进行特定进程的基础监控。 &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;主要需要监控的程序如下： &amp;#160;&amp;#160;&amp;#160;&amp;#160;">
<meta name="twitter:image" content="https://github.com/hcldirgit/image/blob/master/zabbix%E7%9B%91%E6%8E%A7%E8%BF%9B%E7%A8%8B%E7%9A%84CPU%E5%92%8C%E5%86%85%E5%AD%98%E5%8D%A0%E7%94%A8%E9%87%8F/01.jpeg?raw=true">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://hcldirgit.github.io/2017/09/03/Zabbix/17. zabbix监控进程的CPU和内存占用量/"/>





  <title>zabbix监控进程的CPU和内存占用量 | 失落的乐章</title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  




<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
  ga('create', '85*****1', 'auto');
  ga('send', 'pageview');
</script>


  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?87980c**************99ec5e26fb5";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>











  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">失落的乐章</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">技术面前，永远都是学生。</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-message">
          <a href="/message" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-external-link"></i> <br />
            
            留言
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="https://hcldirgit.github.io/2017/09/03/Zabbix/17. zabbix监控进程的CPU和内存占用量/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="失落的乐章">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/0.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="失落的乐章">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">zabbix监控进程的CPU和内存占用量</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-09-03T02:13:44+08:00">
                2017-09-03
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;需要对特定服务进行监控，于是，通过编写脚本获取各个进程占用系统资源的信息，从而使用zabbix采集到这些数据进行特定进程的基础监控。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;主要需要监控的程序如下：</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>nginx、 redis、 mysql、 tomcat、 sentinel、 mongodb、 openfire、 kafka、 zookeeper、 twemproxy、 mycat</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;首先，在agent端编写监控脚本，脚本内容如下：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div><div class="line">88</div><div class="line">89</div><div class="line">90</div><div class="line">91</div><div class="line">92</div><div class="line">93</div><div class="line">94</div><div class="line">95</div><div class="line">96</div><div class="line">97</div><div class="line">98</div><div class="line">99</div><div class="line">100</div><div class="line">101</div><div class="line">102</div><div class="line">103</div><div class="line">104</div><div class="line">105</div><div class="line">106</div><div class="line">107</div><div class="line">108</div><div class="line">109</div><div class="line">110</div><div class="line">111</div><div class="line">112</div><div class="line">113</div><div class="line">114</div><div class="line">115</div><div class="line">116</div><div class="line">117</div><div class="line">118</div><div class="line">119</div><div class="line">120</div><div class="line">121</div><div class="line">122</div><div class="line">123</div><div class="line">124</div><div class="line">125</div><div class="line">126</div><div class="line">127</div><div class="line">128</div><div class="line">129</div><div class="line">130</div><div class="line">131</div><div class="line">132</div><div class="line">133</div><div class="line">134</div><div class="line">135</div><div class="line">136</div><div class="line">137</div><div class="line">138</div><div class="line">139</div><div class="line">140</div><div class="line">141</div><div class="line">142</div></pre></td><td class="code"><pre><div class="line">[zabbix@localhost ~]$ cat zabbix-2.4.4/scripts/processstatus.sh </div><div class="line"><span class="meta">#!/bin/bash</span></div><div class="line"><span class="comment">#license:GPL</span></div><div class="line"><span class="comment">#mail:admin@huxianglin.cn</span></div><div class="line"><span class="comment">#date:2015.06.02</span></div><div class="line"><span class="function"><span class="title">nginx</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"nginx"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$6&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">nginxcpu</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"nginx"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$3&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">redis</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"redis"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$6&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">rediscpu</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"redis"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$3&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">mysql</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"mysql"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$6&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">mysqlcpu</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"mysql"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$3&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">tomcat</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"tomcat"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$6&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">tomcatcpu</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"tomcat"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$3&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">sentinel</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"sentinel"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$6&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">sentinelcpu</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"sentinel"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$3&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">mongodb</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"mongod"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$6&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">mongodbcpu</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"mongod"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$3&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">openfire</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"openfire"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$6&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">openfirecpu</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"openfire"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$3&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">kafka</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"kafka"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$6&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">kafkacpu</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"kafka"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$3&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">zookeeper</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"zookeeper"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$6&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">zookeepercpu</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"zookeeper"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$3&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">twemproxy</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"twemproxy"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$6&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">twemproxycpu</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"twemproxy"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$3&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">mycat</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"mycat"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$6&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">mycatcpu</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"mycat"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$3&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="keyword">case</span> <span class="string">"<span class="variable">$1</span>"</span> <span class="keyword">in</span></div><div class="line">nginx)</div><div class="line">nginx</div><div class="line">;;</div><div class="line">nginxcpu)</div><div class="line">nginxcpu</div><div class="line">;;</div><div class="line">redis)</div><div class="line">redis</div><div class="line">;;</div><div class="line">rediscpu)</div><div class="line">rediscpu</div><div class="line">;;</div><div class="line">mysql)</div><div class="line">mysql</div><div class="line">;;</div><div class="line">mysqlcpu)</div><div class="line">mysqlcpu</div><div class="line">;;</div><div class="line">tomcat)</div><div class="line">tomcat</div><div class="line">;;</div><div class="line">tomcatcpu)</div><div class="line">tomcatcpu</div><div class="line">;;</div><div class="line">sentinel)</div><div class="line">sentinel</div><div class="line">;;</div><div class="line">sentinelcpu)</div><div class="line">sentinelcpu</div><div class="line">;;</div><div class="line">mongodb)</div><div class="line">mongodb</div><div class="line">;;</div><div class="line">mongodbcpu)</div><div class="line">mongodbcpu</div><div class="line">;;</div><div class="line">openfire)</div><div class="line">openfire</div><div class="line">;;</div><div class="line">openfirecpu)</div><div class="line">openfirecpu</div><div class="line">;;</div><div class="line">kafka)</div><div class="line">kafka</div><div class="line">;;</div><div class="line">kafkacpu)</div><div class="line">kafkacpu</div><div class="line">;;</div><div class="line">zookeeper)</div><div class="line">zookeeper</div><div class="line">;;</div><div class="line">zookeepercpu)</div><div class="line">zookeepercpu</div><div class="line">;;</div><div class="line">twemproxy)</div><div class="line">twemproxy</div><div class="line">;;</div><div class="line">twemproxycpu)</div><div class="line">twemproxycpu</div><div class="line">;;</div><div class="line">mycat)</div><div class="line">mycat</div><div class="line">;;</div><div class="line">mycatcpu)</div><div class="line">mycatcpu</div><div class="line">;;</div><div class="line">*)</div><div class="line"><span class="built_in">echo</span> <span class="string">"Usage: <span class="variable">$0</span> &#123;nginx|nginxcpu|redis|rediscpu|mysql|mysqlcpu|tomcat|tomcatcpu|sentinel|sentinelcpu|mongodb|mongodbcpu|openfire|openfirecpu|kafka|kafkacpu|zookeeper|zookeepercpu|twemproxy|twemproxycpu|mycat|mycatcpu&#125;"</span></div><div class="line">;;</div><div class="line"><span class="keyword">esac</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;然后修改脚本的权限，使用：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">chmod +x processstatus.sh</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在zabbix_agentd.con配置文件中末尾增加如下代码：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div></pre></td><td class="code"><pre><div class="line">[zabbix@localhost ~]$ tail -23 zabbix-2.4.4/etc/zabbix_agentd.conf</div><div class="line"><span class="comment">#monitor process</span></div><div class="line">UserParameter=process.nginx.memory,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh nginx</div><div class="line">UserParameter=process.nginx.cpu,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh nginxcpu</div><div class="line">UserParameter=process.redis.memory,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh redis</div><div class="line">UserParameter=process.redis.cpu,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh rediscpu</div><div class="line">UserParameter=process.mysql.memory,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh mysql</div><div class="line">UserParameter=process.mysql.cpu,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh mysqlcpu</div><div class="line">UserParameter=process.tomcat.memory,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh tomcat</div><div class="line">UserParameter=process.tomcat.cpu,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh tomcatcpu</div><div class="line">UserParameter=process.sentinel.memory,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh sentinel</div><div class="line">UserParameter=process.sentinel.cpu,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh sentinelcpu</div><div class="line">UserParameter=process.mongodb.memory,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh mongodb</div><div class="line">UserParameter=process.mongodb.cpu,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh mongodbcpu</div><div class="line">UserParameter=process.openfire.memory,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh openfire</div><div class="line">UserParameter=process.openfire.cpu,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh openfirecpu</div><div class="line">UserParameter=process.kafka.memory,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh kafka</div><div class="line">UserParameter=process.kafka.cpu,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh kafkacpu</div><div class="line">UserParameter=process.zookeeper.memory,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh zookeeper</div><div class="line">UserParameter=process.zookeeper.cpu,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh zookeepercpu</div><div class="line">UserParameter=process.twemproxy.memory,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh twemproxy</div><div class="line">UserParameter=process.twemproxy.cpu,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh twemproxycpu</div><div class="line">UserParameter=process.mycat.memory,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh mycat</div><div class="line">UserParameter=process.mycat.cpu,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh mycatcpu</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;最后重启zabbix_agentd服务</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">pkill zabbix</div><div class="line">zabbix-2.4.4/sbin/zabbix_agentd</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;然后在zabbix服务端使用zabbix_get看能否取到相应的数据，像下面这样就是成功获取到了数据。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@localhost zabbix-2.4.4]<span class="comment"># bin/zabbix_get -s 172.16.1.20 -p 10050 -k process.nginx.memory</span></div><div class="line">184876</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;最后，需要在zabbix中定义模板。模板附件链接在下面。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;zabbix模板下载</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;如果模板无法下载可以在附件中下载模板</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;需要注明的是内存取到的值得单位是KB，所以定义item的时候使用自定义倍数乘以    1000，单位改成Byte，另外CPU占用率的值是带有小数点的一个数，所以在定义item的时    候需要定义值得类型是浮点型，并且该值是占用逻辑单核的CPU占用率，所以需要定义自    定义倍数，我实验中的服务器是2颗CPU，每颗CPU是8核16线程，所以自定义倍数是原来    的基础上除以32，单位改成%就好。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;下面是做好之后的显示效果：</p>
<p><img src="https://github.com/hcldirgit/image/blob/master/zabbix%E7%9B%91%E6%8E%A7%E8%BF%9B%E7%A8%8B%E7%9A%84CPU%E5%92%8C%E5%86%85%E5%AD%98%E5%8D%A0%E7%94%A8%E9%87%8F/01.jpeg?raw=true" alt=""></p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Zabbix/" rel="tag"># Zabbix</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/09/03/Zabbix/16. zabbix监控php状态/" rel="next" title="zabbix监控php状态">
                <i class="fa fa-chevron-left"></i> zabbix监控php状态
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/09/03/Zabbix/18. ZABBIX监控H3C设备的CPU和内存使用率/" rel="prev" title="ZABBIX监控H3C设备的CPU和内存使用率">
                ZABBIX监控H3C设备的CPU和内存使用率 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      

      <section class="site-overview sidebar-panel sidebar-panel-active">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/0.png"
               alt="失落的乐章" />
          <p class="site-author-name" itemprop="name">失落的乐章</p>
           
              <p class="site-description motion-element" itemprop="description">失落的乐章的Blog</p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/">
                <span class="site-state-item-count">627</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">38</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/hcldirgit" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">失落的乐章</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Muse
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.1"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.1"></script>



  


  




	





  





  





  






  





  

  

  

  

  

  

</body>
</html>
